CURRENT_PATH=`pwd`
PROCESSES=`jps`

EXISTPROCESS=0
HASKEY=0

for p in $PROCESSES; do
    if [ $p = "spider-schedule-0.0.1.jar" ] ; then
        EXISTPROCESS=1
    fi
    if [ $EXISTPROCESS = 1 ] ; then
        HASKEY=1
        break
    fi
done

if [ $HASKEY = 1 ] ; then
    echo "Control script \"spider-schedule\" has already running, exit!"
    exit 0
fi

rm logs/* -rf
export QWS_CACHE_HOME=/app/.qws/cache/
export XDG_CACHE_HOME=/app/.cache/
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:`pwd`/script/target/lib:$LD_LIBRARY_PATH
cd src/java/src/spider-schedule/
nohup java -jar target/spider-schedule-0.0.1.jar > app.log 2>&1 &
echo $! > $CURRENT_PATH/app.pid
cd -

#cd src/java/src/spider-data-extract/
#nohup java -jar target/spider-data-extract-0.0.1-SNAPSHOT.jar > app.log 2>&1 &
#echo $! > $CURRENT_PATH/extract.pid
#cd -
